home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / hash / endian.c next >
Encoding:
C/C++ Source or Header  |  1994-03-25  |  1.7 KB  |  55 lines  |  [TEXT/R*ch]

  1. /* @(#)endian.c    10.1 3/25/94 08:03:57 */
  2. /*
  3.  * endian - Determine the byte order of a long on your machine.
  4.  *
  5.  * Big Endian:        Amdahl, 68k, Pyramid, Mips, Sparc, ...
  6.  * Little Endian:   Vax, 32k, Spim (Dec Mips), i386, i486, ...
  7.  *
  8.  * This makefile was written by:
  9.  *
  10.  *     Landon Curt Noll  (chongo@toad.com)    chongo <was here> /\../\
  11.  *
  12.  * This code has been placed in the public domain.  Please do not 
  13.  * copyright this code.
  14.  *
  15.  * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH  REGARD  TO
  16.  * THIS  SOFTWARE,  INCLUDING  ALL IMPLIED WARRANTIES OF MER-
  17.  * CHANTABILITY AND FITNESS.  IN NO EVENT SHALL  LANDON  CURT
  18.  * NOLL  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  19.  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM  LOSS  OF
  20.  * USE,  DATA  OR  PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  21.  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR  IN
  22.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  23.  *
  24.  * See shsdrvr.c and md5drvr.c for version and modification history.
  25.  */
  26.  
  27. #include <stdio.h>
  28.  
  29. /* byte order array */
  30. char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59,
  31.          (char)0x01, (char)0x23, (char)0x45, (char)0x67 };
  32.  
  33. main()
  34. {
  35.     /* pointers into the byte order array */
  36.     int *intp = (int *)byte;
  37.  
  38.     /* Print the standard <machine/endian.h> defines */
  39.     printf("#define BIG_ENDIAN\t4321\n");
  40.     printf("#define LITTLE_ENDIAN\t1234\n");
  41.  
  42.     /* Determine byte order */
  43.     if (intp[0] == 0x12364859) {
  44.     /* Most Significant Byte first */
  45.     printf("#define BYTE_ORDER\tBIG_ENDIAN\n");
  46.     } else if (intp[0] == 0x59483612) {
  47.     /* Least Significant Byte first */
  48.     printf("#define BYTE_ORDER\tLITTLE_ENDIAN\n");
  49.     } else {
  50.     fprintf(stderr, "Unknown int Byte Order, set BYTE_ORDER in Makefile\n");
  51.     exit(1);
  52.     }
  53.     exit(0);
  54. }
  55.